package org.seven.jrdp.web.mgt.sys;

import java.util.List;

import org.seven.jrdp.biz.sys.model.SysRes;
import org.seven.jrdp.biz.sys.service.SysResService;
import org.seven.jrdp.commons.model.Result;
import org.seven.jrdp.commons.model.TreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/mgt/sys/res")
public class SysResController {
	@Autowired
	private SysResService sysResService;

	@GetMapping("/{view}")
	public ModelAndView view(@PathVariable String view) {
		return new ModelAndView("mgt/sys/res/res_" + view);
	}

	@PostMapping("/find")
	public List<SysRes> find() {
		List<SysRes> list = sysResService.find();
		return list;
	}

	@RequestMapping("/get")
	public SysRes get(String id) {
		SysRes SysRes = sysResService.get(id);
		return SysRes;
	}

	@PostMapping("/insert")
	public Result insert(SysRes SysRes) {
		sysResService.insert(SysRes);
		return Result.SUCCESS;
	}

	@PostMapping("/update")
	public Result update(SysRes SysRes) {
		sysResService.update(SysRes);
		return Result.SUCCESS;
	}

	@PostMapping("/delete")
	public Result delete(String id) {
		sysResService.delete(id);
		return Result.SUCCESS;
	}

	@RequestMapping("/tree")
	public List<TreeNode> tree() {
		List<TreeNode> list = sysResService.findTree();
		return list;
	}
}